package com.work.customer.dao;


import com.work.customer.pojo.Role;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface RoleMapper extends Mapper<Role>{
    //向角色权限表添加数据
    @Insert("insert into t_role_menu value (#{rid},#{mid})")
    void add(@Param("rid") Integer rid,@Param("mid") Integer mid);

    @Update("update t_role set role=#{role},info=#{info},category=#{category} where id=#{id}")
   void update(Role role);

    /*@Select("<script>select * from t_role <if test=\"queryString!=null and queryString!=''\">where role=#{queryString} or info=#{queryString}</if></script>")
    List<Role> find(@Param("queryString") String queryString);*/

    //删除角色权限中间表数据
    @Delete("delete from t_role_menu where rid=#{rid} and mid=#{mid}")
    void deleteById(@Param("rid") Integer rid,@Param("mid")Integer mid);


    //添加用户角色表数据
    @Insert("insert into t_cust_user_role value (#{cuid},#{rid})")
    void addByRid(@Param("cuid")Integer cuid, @Param("rid")Integer rid);

    //删除用户角色表数据
    @Delete("delete from t_cust_user_role where cuid=#{cuid} and rid=#{rid}")
    void deleteByUid(@Param("cuid")Integer cuid, @Param("rid")Integer rid);

    ////通过角色id查询中间表获取权限id
    @Select("select mid from t_role_menu where rid=#{rid}")
    Integer[] findByRid(Long id);
}
